#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年7月22日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]


'''mac探测次数'''

class AnalyzeRawdata():
    def __init__(self):
        pass
    
    def stat_mac_probe_times(self,rawfile=''):
        #2015-07-21.048d38621ac0.30:a8:db:d0:d0:24.15:23:22.-86.2015-07-21 15:23:26
        datas = {}
        for line in open(rawfile).read().split('\n'):
            lineList = line.split('.')
            if len(lineList)!=6:continue
            mac = lineList[2]
            if mac not in datas.keys():
                datas[mac]=0
            datas[mac]+=1
        return datas
    
    
    def show_precent_by_probe_times(self,datas={},show=False):
        ndatas = {}
        for mac,times in datas.items():
            if times not in ndatas.keys():
                ndatas[times] = 0
            ndatas[times]+=1
        if show:
            for times , macs in  ndatas.items():
                print times , macs
        return ndatas
    
    
    def stat_rssi(self,rawfile='',startHour=0,endHour=23,show=False):
        datas = {}
        for line in open(rawfile).read().split('\n'):
            lineList = line.split('.')
            if len(lineList)!=6:continue
            mac = lineList[2]
            stime  = lineList[3]
            hour = int(stime.split(':')[0])
            if hour not in range(startHour,endHour)+[endHour]:continue
            rssi = lineList[4]
            if rssi not in datas.keys():
                datas[rssi] = 0
            datas[rssi]+=1
        if show:
            for rssi , count in datas.items():
                print rssi,count
        return datas
            
    
    
if __name__=='__main__':
    myAnalyzeRawdata = AnalyzeRawdata()
    rawfile = '/Users/chenyongbing/Downloads/32010078.txt/048d38621ac0'
    #datas = myAnalyzeRawdata.stat_mac_probe_times(rawfile)
    #ndatas = myAnalyzeRawdata.show_precent_by_probe_times(datas)
    myAnalyzeRawdata.stat_rssi(rawfile=rawfile, startHour=9, endHour=13, show=True)
        
        
    
    